
class MxcSlider < Qt::Slider
	def initialize(orientation, parent = nil, name = nil)
		super(orientation, parent, name)

		installEventFilter(self)
	end

	def setPosition(val, changePosition)
		if changePosition
			setValue(val)
			emit sliderMoved(val)
		end
	end

	def wheelEvent(event)
		newVal = 0
		newVal = event.delta > 0 ? value - 10 : value + 10
		newVal = newVal < -100 ? -100 : newVal
		setPosition(newVal, true)
		event.accept
	end

		
	def eventFilter(obj, event)
		if obj == self && (event.type == Qt::Event::MouseButtonPress ||
				   event.type == Qt::Event::MouseButtonDblClick)
			srect = sliderRect
			if srect.contains(event.pos) || event.button != Qt::LeftButton
				return false
			end

			range = maxValue - minValue
			pos = orientation == Qt::Horizontal ? event.pos.x : event.pos.y
			maxpos = orientation == Qt::Horizontal ? width : height
			value = pos * range / maxpos + minValue

			if Qt::Application.reverseLayout
				value = maxValue - (value - minValue)
			end

			setPosition(value, true)
			return true
		else
			return false
		end
	end
end
